﻿
@{
    ViewData["Title"] = "InStoreIndex";
    Layout = "~/Views/Share/_LayoutBody.cshtml";
}
<div class="list-wall">
    <div class="list-top">
        <div class="layui-btn-group">
            <div class="layui-form-item" style="margin-bottom:5px">
                <div class="layui-input-inline" style="width:75px">
                    <label style="padding-left:20px;padding-top:5px">查询条件:</label>
                </div>
                <div class="layui-input-inline" style="width:200px;z-index:100">
                    <div class="ui-filter" style="width: 200px;">
                        <div   id="btn_Search"  class="ui-filter-text">
                            <strong id="StartTime">2018-01-01</strong>  至 <strong id="EndTime">现在</strong>
                            <i authorize="yes" style="float:right;padding-right:2px" class="layui-icon ">&#xe625;</i>
                        </div>
                        <div id="list-Search" class="ui-filter-list" style="width: 450px;">
                            <form id="form1" class="layui-form">
                                <table class="form">
                                    <tr>
                                        <th class="formTitle">单据日期:</th>
                                        <td class="formValue" colspan="3">
                                            <div style="float: left; width: 45%;">
                                                <input type="text" name="StartDate" autocomplete="off" class="form-control input-sm layui-input" id="StartDate">
                                            </div>
                                            <div style="float: left; width: 10%; text-align: center;">
                                                至:
                                            </div>
                                            <div style="float: left; width: 45%;">
                                                <input id="EndDate" name="EndDate" type="text" autocomplete="off" class="form-control input-sm" />
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th class="formTitle">入库单号:</th>
                                        <td class="formValue" colspan="3">
                                            <input id="BillID" name="BillID" type="text" autocomplete="off" class="form-control input-sm" />
                                        </td>

                                    </tr>
                                    <tr>
                                        <th class="formTitle">供应商:</th>
                                        <td class="formValue" colspan="3">
                                            <input id="SupName" name="SupName" type="text" autocomplete="off" class="form-control input-sm" />
                                        </td>

                                    </tr>
                                    <tr>
                                        <th class="formTitle">验收员:</th>
                                        <td class="formValue" colspan="3">
                                            <input id="JSName" name="JSName" type="text" autocomplete="off" class="form-control input-sm" />
                                        </td>

                                    </tr>
                                    <tr>
                                        <th class="formTitle">仓库:</th>
                                        <td class="formValue" colspan="3">
                                            <input id="StoreName" name="StoreName" type="text" autocomplete="off" class="form-control input-sm" />
                                        </td>

                                    </tr>
                                </table>
                            </form>
                            <div style="float:right;padding-right:5px">
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" data-type="Clear" id="Clear"><i class="layui-icon ">&#xe9aa;</i>重置</button>
                                <button type="button" authorize="yes" class="layui-btn layui-btn-sm" data-type="Search" id="Search"><i class="layui-icon ">&#xe615;</i>查询</button>
                            </div>
                        </div>
                    </div>

                </div>

            </div>
        </div>
        <div class="layui-btn-group" style="float:right">
            <button type="button" authorize="yes" class="layui-btn layui-btn-xs" data-type="SH" id="SH"><i class="layui-icon">&#xe672;</i> 审核确认</button>
            <button type="button" authorize="yes" class="layui-btn layui-btn-xs" data-type="NOSH" id="NOSH"><i class="layui-icon">&#xe65c;</i> 撤销审核</button>
            <button type="button" authorize="yes" class="layui-btn layui-btn-xs" data-type="Excel" id="Excel"><i class="layui-icon ">&#xe601;</i> 导出</button>
        </div>

        <div class="layui-btn-group" style="float:right">
            <button type="button" authorize="yes" class="layui-btn layui-btn-xs" data-type="Add" id="Add"><i class="layui-icon">&#xe61f;</i> 新增</button>
            <button type="button" authorize="yes" class="layui-btn layui-btn-xs" data-type="Edit" id="Edit"><i class="layui-icon">&#xe642;</i> 修改</button>
            <button type="button" authorize="yes" class="layui-btn layui-btn-xs" data-type="Del" id="Del"><i class="layui-icon ">&#xe640;</i> 删除</button>
        </div>
    </div>
    <div class="gridPanel">
        <table id="list1" class="table table-condensed"></table>
        <div id="pager1"></div>
    </div>
</div>
<script>$('.list-top').authorizeButton()</script>
<script>
    var datas = "";
    var CX_StrSearch = "";
    var bodyheight = 0;
    $(function () {
        layui.use(['table', 'form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , table = layui.table;
            var strdate = new Date().Format("yyyy-MM-dd");
            laydate.render({
                elem: '#StartDate',//制定元素
                type: 'date',
                show: false,//默认显示
                position: 'fixed',
                value: strdate,
                isInitValue: true, //是否允许填充初始值，默认为 true
            });
            laydate.render({
                elem: '#EndDate',//制定元素
                type: 'date',
                show: false,//默认显示
                position: 'fixed',
                isInitValue: true, //是否允许填充初始值，默认为 true
            });
            $("#StartTime").html(strdate);
            datas = $('#form1').formGetModel();
            form.render();
        });

        bodyheight = document.body.scrollHeight;
        $("#list1").jqGrid({
            styleUI: 'Bootstrap',
            url: '/InStore/InStoreList',
            datatype: "json",
            jsonReader: {
                repeatitems: false
            },
            colModel: [
                { label: 'id', name: 'id', index: 'id', key: true, width: 75, hidden: true },
                { label: '单据日期', name: 'BillDate', index: 'BillDate', formatter: "date", formatoptions: { newformat: 'Y-m-d' }, width: 100, align: 'center' },
                { label: '入库单号', name: 'BillID', index: 'BillID', width: 180, align: 'center' },
                { label: '验收员', name: 'YSName', index: 'YSName', width: 80, align: 'center' },
                { label: '供应商', name: 'SupName', index: 'SupName', width: 180, align: 'center' },
                { label: '仓库', name: 'StoreName', index: 'StoreName', width: 120, align: 'center' },
                { label: '金额', name: 'Sum', index: 'Sum', width: 120, align: 'center' },
                { label: '备注', name: 'BZ', index: 'BZ', width: 100, align: 'center' },
                {
                    label: '审核状态', name: 'SHStatus', index: 'SHStatus', width: 100, align: 'center', formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == "0") {
                            return '<span class="layui-badge layui-bg-red">未审核</span>';
                        } else if (cellvalue == "1") {
                            return '<span class="layui-badge layui-bg-green">已审核</span>';
                        } else {
                            return '<span class="layui-badge layui-bg-orange">未知</span>';
                        }
                    }
                },
                { label: '制单人', name: 'CreateName', index: 'CreateName', width: 100, align: 'center' },
                { label: '审核人', name: 'SHName', index: 'SHName', width: 100, align: 'center' },
                { label: '关联订单号', name: 'OrderBillID', index: 'OrderBillID', width: 100, align: 'center' },

            ],
            width: "99%",
            autowidth: true,
            height: $(window).height() - 110,
            rowNum: 30,//一页显示多少条
            rowList: [10, 20, 30, 50, 100],//可供用户选择一页显示多少条
            pager: '#pager1',//表格页脚的占位符(一般是div)的id
            sortname: 'id',//初始化的时候排序的字段
            sortorder: "desc",//排序方式,可选desc,asc
            mtype: "post",//向后台请求数据的ajax的类型。可选post,get
            viewrecords: true,
            shrinkToFit: false,
            postData:{'Search':datas },
            rownumbers: true,
            subGrid: true,  // (1)开启子表格支持
            subGridRowExpanded: function (subgrid_id, row_id) {  // (2)子表格容器的id和需要展开子表格的行id，将传入此事件函数
                var subgrid_table_id;
                subgrid_table_id = subgrid_id + "_t";   // (3)根据subgrid_id定义对应的子表格的table的id

                var subgrid_pager_id;
                subgrid_pager_id = subgrid_id + "_pgr"  // (4)根据subgrid_id定义对应的子表格的pager的id

                // (5)动态添加子报表的table和pager
                $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + subgrid_pager_id + "' class='scroll'></div>");

                //$("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table>");

                // (6)创建jqGrid对象
                $("#" + subgrid_table_id).jqGrid({
                    url: "/InStore/InStore_MXList?&id=" + row_id,  // (7)子表格数据对应的url，注意传入的contact.id参数
                    datatype: "json",
                    styleUI: 'Bootstrap',
                    colModel: [
                        { label: 'id', name: 'id', index: 'id', key: true, width: 75, hidden: true },
                        { label: '商品名称', name: 'GoodName', index: 'GoodName', width: 140, align: 'center' },
                        { label: '单位', name: 'DW', index: 'DW', width: 80, align: 'center' },
                        { label: '规格', name: 'GGType', index: 'GGType', width: 100, align: 'center' },
                        { label: '型号', name: 'ModelType', index: 'ModelType', width: 75, align: 'center' },
                        { label: '生产厂家', name: 'SCCJ', index: 'SCCJ', width: 75, align: 'center' },
                        { label: '生产批号', name: 'SCPH', index: 'SCPH', width: 75, align: 'center' },
                        { label: '灭菌批号', name: 'MJPH', index: 'MJPH', width: 75, align: 'center' },
                        { label: '生产日期', name: 'scDate', index: 'scDate', formatter: "date", formatoptions: { newformat: 'Y-m-d' }, width: 75, align: 'center' },
                        { label: '有效期至', name: 'yxqDate', index: 'yxqDate', formatter: "date", formatoptions: { newformat: 'Y-m-d' }, width: 75, align: 'center' },
                        { label: '单价', name: 'Price', index: 'Price', width: 75, align: 'center' },
                        { label: '数量', name: 'Num', index: 'Num', width: 80, align: 'center' },
                        { label: '金额', name: 'Sum', index: 'Sum', width: 80, align: 'center' },
                        { label: '备注', name: 'BZ', index: 'BZ', width: 80, align: 'center' },
                    ],
                    jsonReader: {   // (8)针对子表格的jsonReader设置
                        repeatitems: false
                    },
                    loadComplete: function (xhr) {  //隐藏滚动条
                        $("#" + subgrid_table_id).closest(".ui-jqgrid-bdiv").css({ 'overflow-y': 'hidden' });
                    },
                    width: "100%",
                    autowidth: true,
                    mtype: "post",
                    rowNum: 20,
                    rowList: [10, 20, 30, 50, 100],
                    pager: subgrid_pager_id,
                    sortname: 'id',
                    sortorder: "asc",
                    height: '100%',
                    rownumbers: true,
                    shrinkToFit: false,

                });
            },
            subGridRowColapsed: function (subgrid_id, row_id) {
                // this function is called before removing the data
                var subgrid_table_id;
                subgrid_table_id = subgrid_id + "_t";
                $("#" + subgrid_table_id).remove();
            },
        });
        $(window).bind('resize', function () {
            $("#list1").setGridWidth($(window).width() - 20);
            $("#list1").setGridHeight($(window).height() - 110);
        }).trigger('resize');

    });


    $(function () {
        $.hands = {
            Add: function () {
                var url = "/InStore/AddEditOrderIndex" + "?types=add";
                if (top.layui.index) {
                    top.layui.index.openTabsPage(url, "新增入库单")
                } else {
                    window.open(url)
                }
                //$.FromOpen('StoreFromAdd', '新增仓库', '/StoreInfo/AddIndex', '600px', '350px', '1000');
            },
            Edit: function () {
                var id = $("#list1").jqGrid('getGridParam', 'selrow');//根据点击行获得点击行的id（id为jsonReader: {id: "id" },）
                var rowData = $("#list1").jqGrid("getRowData", id);//根据上面的id获得本行的所有数据
                var ids = rowData.id; //获得制定列的值 （UserID 为colModel的name）
                if (ids == null || ids == undefined) {
                    layer.msg("请选择一行", { icon: 2 });
                    return;
                }
                if (rowData.SHStatus == '<span class="layui-badge layui-bg-green">已审核</span>') {

                    layer.msg("单据已审核", { icon: 2 });
                    return;
                }
                var url = "/InStore/AddEditOrderIndex" + "?ids=" + ids + "&types=edit";
                if (top.layui.index) {
                    top.layui.index.openTabsPage(url, "修改入库单")
                } else {
                    window.open(url)
                }

            },
            Del: function () {
                var id = $("#list1").jqGrid('getGridParam', 'selrow');//根据点击行获得点击行的id（id为jsonReader: {id: "id" },）
                var rowData = $("#list1").jqGrid("getRowData", id);//根据上面的id获得本行的所有数据
                var ids = rowData.id; //获得制定列的值 （UserID 为colModel的name）
                if (ids == null || ids == undefined) {
                    layer.msg("请选择一行", { icon: 2 });
                    return;
                }
                layer.confirm('确认要删除选择的数据吗？', {
                    title: "删除采购入库单",
                    btn: ['确定', '关闭'] //按钮
                }, function (index, layero) {
                    $.loading(true, "正在删除数据");
                    window.setTimeout(function () {
                        $.ajax({
                            url: "/InStore/DeleteBill/",
                            data: { ids: ids },
                            type: "post",
                            dataType: "json",
                            success: function (data) {
                                $.loading(false);
                                if (data.errorMsg) {
                                    layer.msg(data.errorMsg, { icon: 2 });
                                }
                                else {
                                    $("#list1").trigger("reloadGrid");

                                }
                            },
                            error: function () {
                                $.loading(false);

                            },
                            complete: function () {
                                $.loading(false);
                            }
                        });

                    }, 500);
                    layer.close(index);

                }, function () {
                    return true;
                });
            },
            SH: function () {
                var id = $("#list1").jqGrid('getGridParam', 'selrow');//根据点击行获得点击行的id（id为jsonReader: {id: "id" },）
                var rowData = $("#list1").jqGrid("getRowData", id);//根据上面的id获得本行的所有数据
                var ids = rowData.id; //获得制定列的值 （UserID 为colModel的name）
                if (ids == null || ids == undefined) {
                    layer.msg("请选择一行", { icon: 2 });
                    return;
                }
                layer.confirm('确认要审核选择的数据吗？', {
                    title: "审核采购入库单",
                    btn: ['确定', '关闭'] //按钮
                }, function (index, layero) {
                    $.loading(true, "正在审核数据");
                    window.setTimeout(function () {
                        $.ajax({
                            url: "/InStore/SHBill/",
                            data: { ids: ids },
                            type: "post",
                            dataType: "json",
                            success: function (data) {
                                $.loading(false);
                                if (data.errorMsg) {
                                    layer.msg(data.errorMsg, { icon: 2 });
                                }
                                else {
                                    $("#list1").trigger("reloadGrid");

                                }
                            },
                            error: function () {
                                $.loading(false);

                            },
                            complete: function () {
                                $.loading(false);
                            }
                        });

                    }, 500);
                    layer.close(index);

                }, function () {
                    return true;
                });

            },
            NOSH: function () {

                var id = $("#list1").jqGrid('getGridParam', 'selrow');//根据点击行获得点击行的id（id为jsonReader: {id: "id" },）
                var rowData = $("#list1").jqGrid("getRowData", id);//根据上面的id获得本行的所有数据
                var ids = rowData.id; //获得制定列的值 （UserID 为colModel的name）
                if (ids == null || ids == undefined) {
                    layer.msg("请选择一行", { icon: 2 });
                    return;
                }
                layer.confirm('确认要反审核选择的数据吗？', {
                    title: "反审核采购入库单",
                    btn: ['确定', '关闭'] //按钮
                }, function (index, layero) {
                    $.loading(true, "正在反审核数据");
                    window.setTimeout(function () {
                        $.ajax({
                            url: "/InStore/NOSHBill/",
                            data: { ids: ids },
                            type: "post",
                            dataType: "json",
                            success: function (data) {
                                $.loading(false);
                                if (data.errorMsg) {
                                    layer.msg(data.errorMsg, { icon: 2 });
                                }
                                else {
                                    $("#list1").trigger("reloadGrid");

                                }
                            },
                            error: function () {
                                $.loading(false);

                            },
                            complete: function () {
                                $.loading(false);
                            }
                        });

                    }, 500);
                    layer.close(index);

                }, function () {
                    return true;
                });
            },
            Search: function () {
                datas = $('#form1').formGetModel();
                $.loading(true, "正在查询数据");
                window.setTimeout(function () {
                    $("#list1").jqGrid('setGridParam', {
                        postData: { 'Search': datas },
                        //page: 1
                    }).trigger("reloadGrid");

                    $.loading(false);
                }, 500);
                var startdate = $("#StartDate").val();
                $("#StartTime").html(startdate);
                var enddate = $("#EndDate").val();

                if (enddate != undefined && enddate != "" && enddate != null) {

                    $("#EndTime").html(enddate);
                }
                else {
                    $("#EndTime").html('现在');
                }

                $('#list-Search').hide();
            },
            Excel: function () {
                $.loading(true, "正在提交数据");
                window.setTimeout(function () {
                    var funFrom = document.createElement("form");
                    document.body.appendChild(funFrom);
                    funFrom.action = '/InStore/GetFile/';
                    funFrom.method = 'post';
                    var total = $("#list1").jqGrid('getGridParam', 'records');
                    if (parseInt(total) > 0) {
                        var newStrSearch = document.createElement("input");
                        newStrSearch.setAttribute("name", "JsonSearch");
                        newStrSearch.setAttribute("type", "hidden");
                        newStrSearch.setAttribute("value", JSON.stringify(datas));
                        funFrom.appendChild(newStrSearch);
                        funFrom.submit();
                    } else {
                        top.layer.msg("空数据导出失败", { icon: 2 });
                    }

                }, 500);
                $.loading(false);
            },
            BtnSearch: function () {
                var display = $('#list-Search').css('display');
                if (display == 'none') {
                    $("#list-Search").show()

                } else {
                    $('#list-Search').hide();

                }

            },
            Clear: function () {
                $('#form1')[0].reset();
                var strdate = new Date().Format("yyyy-MM-dd");
                $("#StartDate").val(strdate);

            },
            init: function () {
                $('#Add').on('click', $.hands.Add);
                $('#Edit').on('click', $.hands.Edit);
                $('#Del').on('click', $.hands.Del);
                $('#Search').on('click', $.hands.Search);
                $('#Excel').on('click', $.hands.Excel);
                $('#SH').on('click', $.hands.SH);
                $('#NOSH').on('click', $.hands.NOSH);
                $('#Clear').on('click', $.hands.Clear);
                $('#btn_Search').on('click', $.hands.BtnSearch);
            }
        }
        $(function () {
            $.hands.init();
        });
    });

</script>
<style>
    #form1 > td, th {
        padding: 5px 0px 5px 0px;
    }

    .ui-jqgrid {
        z-index: 99;
    }
</style>








